package com.homwee.factory;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.homwee.factory.util.Contants;
import com.homwee.listMenu.util.ExtraAdapter;
import com.homwee.tvap.common.ap.ComSettingManager;
import com.homwee.tvap.common.srvfunc.FactorySetting;
import com.mediatek.twoworlds.factory.MtkTvFApiInformation;
import com.mediatek.twoworlds.factory.MtkTvFApiSystem;

import android.app.Activity;
import android.os.Bundle;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ListView;

public class FactoryDataIndexInfoActivity extends Activity {
	private String[] names=null;
	private String[] values=null;
	
	private String[] names2=null;
	private String[] values2=null;

	
	public static FactoryDataIndexInfoActivity instance=null;
	public ComSettingManager mcomSettingManager;
	public FactorySetting factorySetting;
	
	ExtraAdapter adapter=null;
	ExtraAdapter page2adapter=null;
	//ExtraAdapter page3adapter=null;
	ListView listview=null;
	ListView page2listview=null;
	//ListView page3listview=null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		instance=this;
		setContentView(R.layout.menu_list_extra);
		ListView listView3=this.findViewById(R.id.page3itemListViewExtra);
		listView3.setVisibility(View.GONE);
		initData();
		
	}
	private void initData() {
		// TODO Auto-generated method stub
		mcomSettingManager=ComSettingManager.getInstance(this);
		factorySetting = mcomSettingManager.getFactory();
		Map<String, Object> mDataIndex = FactoryIniReadService.readIni(factorySetting.getDataIndex());

		String dataIndex=factorySetting.getDataIndex();
		String m_pPanelName=((Map<String, String>) mDataIndex.get("panel")).get("m_pPanelName");
		String m_PQBinPathName=((Map<String, String>) mDataIndex.get("panel")).get("PQBinPathName");
		String m_pIniFile=((Map<String, String>) mDataIndex.get("Hdr")).get("m_pIniFile");
		String m_pEdidBinPath=((Map<String, String>) mDataIndex.get("EDID")).get("m_pEdidBinPath");
		String m_pIniGammaTable_File=((Map<String, String>) mDataIndex.get("PQ_general")).get("m_pIniGammaTable_File");
		String m_pIniNLA_File=((Map<String, String>) mDataIndex.get("PQ_general")).get("m_pIniNLA_File");
		String m_pIniOsdMapping_File=((Map<String, String>) mDataIndex.get("PQ_general")).get("m_pIniOsdMapping_File");
		String m_pConfigDefaultValue_File=((Map<String, String>) mDataIndex.get("acfg")).get("m_pConfigDefaultValue_File");
		String m_dolby_3d_lut0=MtkTvFApiInformation.getInstance().getIniParameter(
				m_pIniFile,"dolby_level:dolby_3d_lut0");

		String m_pBootLogoMusicCfg_File=((Map<String, String>) mDataIndex.get("BootLogoMusic")).get("m_pBootLogoMusicCfg_File");
		String m_pCustomizationFunc_File=((Map<String, String>) mDataIndex.get("Misc")).get("m_pCustomizationFunc_File");
		String m_pSettingsConfig_File=((Map<String, String>) mDataIndex.get("apk")).get("m_pSettingsConfig_File");
		String m_pInputSourceConfig_File=((Map<String, String>) mDataIndex.get("InputSource")).get("m_pInputSourceConfig_File");
		
		names=new String[]{"DataIndex","m_pPanelName","PQBinPathName","m_pIniFile","m_pEdidBinPath","m_pIniGammaTable_File",
				"m_pIniNLA_File","m_pIniOsdMapping_File","m_pConfigDefaultValue_File"};
		values=new String[]{dataIndex,m_pPanelName,m_PQBinPathName,m_pIniFile,m_pEdidBinPath,m_pIniGammaTable_File,
				m_pIniNLA_File,m_pIniOsdMapping_File,m_pConfigDefaultValue_File};
		
		names2=new String[]{"dolby_3d_lut0 ","m_pBootLogoMusicCfg_File","m_pCustomizationFunc_File","m_pSettingsConfig_File",
				"m_pInputSourceConfig_File"};
		values2=new String[]{m_dolby_3d_lut0,m_pBootLogoMusicCfg_File,m_pCustomizationFunc_File,m_pSettingsConfig_File,
				m_pInputSourceConfig_File};

		
		for(int i=0;i<values.length;i++){
			if(TextUtils.isEmpty(values[i])){
				values[i]="null";
			}
		}

		for(int i=0;i<values2.length;i++){
			if(TextUtils.isEmpty(values2[i])){
				values2[i]="null";
			}
		}

		
		List<Map<String,Object>> listitem=new ArrayList<Map<String,Object>>();
		for(int i=0;i<names.length;i++){
			Map<String,Object> showitem=new HashMap<String,Object>();
			showitem.put("names", names[i]);
			showitem.put("values", values[i]);
			listitem.add(showitem);
		}
		List<Map<String,Object>> page2listitem=new ArrayList<Map<String,Object>>();
		for(int i=0;i<names2.length;i++){
			Map<String,Object> showitem=new HashMap<String,Object>();
			showitem.put("names", names2[i]);
			showitem.put("values", values2[i]);
			page2listitem.add(showitem);
		}

				
		adapter =new ExtraAdapter(listitem, getApplicationContext(),2);
		listview=(ListView)findViewById(R.id.itemListViewExtra);
		listview.setAdapter(adapter);
		
		page2adapter=new ExtraAdapter(page2listitem, getApplicationContext(),2);
		page2listview=(ListView)findViewById(R.id.page2itemListViewExtra);
		page2listview.setAdapter(page2adapter);

		
	}



	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		switch(keyCode){
		case KeyEvent.KEYCODE_MENU:
		case KeyEvent.KEYCODE_BACK:
			finish();
			break;
		}
		return super.onKeyDown(keyCode, event);
	}

}
